<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 组件-选择优惠券弹窗 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->

<template>
	<view class="component-modal-coupon-select" @click.stop>
		<uni-popup ref="popupModal" type="bottom" :safe-area="false" @change="onChange">
			<view class="popup-box" :style="{'--theme-color': themeColor}">
				<view class="popup-header">
					<view class="title">请选择优惠卡券</view>
					<image class="close" src="/static/close.png" mode="aspectFit" @click="onClose"></image>
				</view>
				<view class="popup-content flex-column">
					<view class="content-tips">请根据自身情况进行选择</view>
					<scroll-view scroll-y class="content-list" @scrolltolower="scrolltolower" v-if="showData.length">
						<view class="list-item flex align-items-center" v-for="item in showData" :key="item.id" @click="changeCoupon(item.id, item.discount_price)">
							<view class="item-amount">￥<text class="text">{{item.discount_price}}</text></view>
							<view class="item-connect">
								<view class="connect-circle"></view>
								<view class="connect-line"></view>
								<view class="connect-circle"></view>
							</view>
							<view class="item-info flex-item">
								<view class="info-title">{{item.name}}</view>
								<view class="info-subtitle">可用于代驾扣除费用</view>
								<view class="info-expiration">{{item.expire_date}}</view>
							</view>
							<view class="item-radio" :class="{active: selectCoupon.id == item.id}">
								<image src="/static/tick.png" mode="aspectFill" v-if="selectCoupon.id == item.id"></image>
							</view>
						</view>
					</scroll-view>
					<empty top="32rpx" title="暂无相关内容~" v-else></empty>
				</view>
				<view class="popup-btn">
					<view class="btn confirm" @click="onConfirm" v-if="showData.length">确认选择</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		name: "componentModalCouponSelect",
		props: ["showData"],
		data() {
			return {
				// 已选优惠券
				selectCoupon: {},
			};
		},
		computed: {
			...mapState({
				themeColor: state => state.app.themeColor,
			})
		},
		methods: {
			// 打开模态框
			open(value) {
				this.selectCoupon = value || {}
				this.$refs.popupModal.open()
			},
			// 关闭弹窗
			onClose() {
				this.$refs.popupModal.close()
			},
			// 改变事件
			onChange(e) {
				this.$emit("onChange", e.show)
			},
			// 改变选择优惠券
			changeCoupon(id, price) {
				if (this.selectCoupon && this.selectCoupon.id == id) this.selectCoupon = {}
				else this.selectCoupon = { id, price }
			},
			// 滚动到底部
			scrolltolower() {
				this.$emit("onBottom")
			},
			// 确认选择
			onConfirm() {
				this.$emit("confirm", this.selectCoupon)
				this.onClose()
			},
		},
	}
</script>

<style lang="scss">
	.component-modal-coupon-select {
		position: relative;
		z-index: 999;

		.popup-box {
			background: #FFFFFF;
			border-radius: 40rpx 40rpx 0 0;
			padding: 48rpx 48rpx 0;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.popup-header {
				display: flex;
				align-items: center;

				.title {
					color: #242629;
					font-size: 32rpx;
					font-weight: 600;
					line-height: 44rpx;
					flex: 1;
				}

				.close {
					width: 48rpx;
					height: 48rpx;
				}
			}

			.popup-content {
				min-height: 300rpx;

				.content-tips {
					color: #8D929C;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
					margin-top: 16rpx;
				}

				.content-list {
					margin-top: 40rpx;
					max-height: 60vh;
					min-height: 25vh;

					.list-item {
						margin-top: 32rpx;
						padding-right: 32rpx;
						border-radius: 32rpx;
						background: #F7F7F7;
						overflow: hidden;
						min-height: 176rpx;

						&:first-child {
							margin-top: 0;
						}

						.item-amount {
							width: 176rpx;
							color: var(--theme-color);
							font-size: 24rpx;
							font-weight: 600;
							line-height: 90rpx;
							padding: 32rpx 0;
							text-align: center;

							.text {
								font-size: 56rpx;
							}
						}

						.item-connect {
							width: 24rpx;
							align-self: stretch;
							display: flex;
							flex-direction: column;
							align-items: center;

							.connect-circle {
								width: 24rpx;
								height: 12rpx;
								border-radius: 0 0 12rpx 12rpx;
								background: #FFF;

								&:last-child {
									border-radius: 12rpx 12rpx 0 0;
								}
							}

							.connect-line {
								flex: 1;
								border: 1px dashed #8D929C;
								margin: 8rpx 0;
							}
						}

						.item-info {
							padding: 32rpx 0;
							margin-left: 24rpx;

							.info-title {
								color: #242629;
								font-size: 28rpx;
								font-weight: 600;
								line-height: 40rpx;
							}

							.info-subtitle {
								margin-top: 4rpx;
								color: #8D929C;
								font-size: 24rpx;
								line-height: 34rpx;
							}

							.info-expiration {
								margin-top: 4rpx;
								color: var(--theme-color);
								font-size: 20rpx;
								line-height: 30rpx;
							}
						}

						.item-radio {
							width: 40rpx;
							height: 40rpx;
							background: #E1E1E1;
							border-radius: 50%;
							margin-left: 24rpx;

							&.active {
								background: var(--theme-color);
							}
						}
					}
				}
			}

			.popup-btn {
				margin-top: 32rpx;
				display: flex;
				justify-content: space-between;
				border-top: 1rpx solid #F6F7FB;
				padding: 0 32rpx 16rpx;

				.btn {
					width: 100%;
					color: #FFF;
					text-align: center;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
					background: var(--theme-color);
					border-radius: 48rpx;
					padding: 28rpx 32rpx;
				}
			}
		}
	}
</style>